package com.example.controller.sys;
import com.example.pojo.Emp;
import com.example.service.impl.EmpServiceImpl;
import com.example.vo.ResultVo;
import com.example.vo.per.EmpTurnover;
import com.example.vo.respvo.EmpVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 员工表 前端控制器
 * </p>
 *
 * @author wsl
 * @since 2022-04-11
 */
@RestController
@RequestMapping("/per/emp")
@Api(tags = "员工管理",value = "")
@CrossOrigin(allowCredentials = "true")
public class EmpController {

    @Autowired
    EmpServiceImpl empService;

    @ApiOperation(value = "查询所有员工信息")
    @GetMapping("/page-info")
    public PageInfo<Emp> getEmpPageInfo(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            String empName,
            String workId,
            Integer positionId,
            Integer deptId,
            String companyName
    ){
        return empService.getEmpPageInfo(pageNum,pageSize, empName, workId, positionId, deptId, companyName);
    }

    @ApiOperation(value = "根据部门编号查询员工")
    @GetMapping("/by-dept")
    public ResultVo getEmpsByDeptId(Integer deptId){
        return empService.getEmpsByDeptId(deptId);
    }

    @GetMapping("/options")
    @ApiOperation(value = "用户下拉框")
    public ResultVo getEmpOptions(){
        return empService.getEmpOptions();
    }

    @PutMapping("/replacementPwd")
    @ApiOperation(value = "重置用户密码")
    public ResultVo replacementUserPwd(@RequestBody Emp emp){
        return empService.replacementUserPwd(emp);
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改用户信息")
    public ResultVo updateEmpInfo(Emp emp){
        if(empService.updateById(emp)){
            return ResultVo.ok();
        }
        return ResultVo.error();
    }

    @PutMapping("/updatePwd")
    @ApiOperation(value = "修改用户密码")
    public ResultVo updateUserPwd(
                                  String oldPwd,
                                  String newPwd,
                                  HttpServletRequest request){
        return empService.updateUserPwd(request,oldPwd,newPwd);
    }

    @GetMapping("/byd/{did}")
    @ApiOperation("排班人员 - 部门")
    public ResultVo getByWorkSchedule(@PathVariable("did") Integer did){
        System.out.println(" ---------------------------------------------------------- ");
        List<EmpVo> empVos = empService.byWorkSceduleList(did);
        if (empVos != null){
            return ResultVo.response(empVos);
        }
        return ResultVo.error();
    }



    @GetMapping("/getDeptEmp")
    @ApiOperation(value = "根据部门获得员工信息")
    public List<Emp> getDeptEmp(String deptName){
        return empService.getDeptEmp(deptName);
    }
}
